home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / udos / rbootcpp / reboot.cpp next >
Encoding:
C/C++ Source or Header  |  1992-07-10  |  2.2 KB  |  100 lines

  1. /**************************************************************************
  2.  
  3. REBOOT.CPP - Performs a warm boot of computer with password checking.
  4.  
  5. Copyright (C) 1992 Joe L Chavez.
  6. Permission is granted to any individual or institution to use, copy, or
  7. redistribute this software so long as all of the original files are included
  8. unmodified, that it is not sold for profit, and that this copyright notice
  9. is retained.
  10.  
  11. I have include the source code so that your password can be encoded into
  12. the program and recompiled. This is the safest way.
  13.  
  14.  
  15. ***************************************************************************/
  16.  
  17. #include <dos.h>
  18. #include <ctype.h>
  19. #include <string.h>
  20. #include <conio.h>
  21. #include <fstream.h>
  22.  
  23. #define CONTINUE 1
  24.  
  25. // Control Break handler that intercepts and does nothing
  26. // with a control-break
  27.  
  28. int c_break(void)
  29. {
  30.      return (CONTINUE);
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36.     ctrlbrk(c_break);
  37.  
  38.  
  39.     // ************** Get the current date and time and write to
  40.     // the file boot.log with appending.
  41.     // If the file does not exist then no output is written.
  42.  
  43.     ofstream ofile;
  44.  
  45.     ofile.open("boot.log", ios::out|ios::ate);
  46.  
  47.     if(ofile) {
  48.         struct dosdate_t today;
  49.         struct dostime_t now;
  50.  
  51.         _dos_getdate(&today);
  52.         _dos_gettime(&now);
  53.         ofile << today.year << "/"
  54.                     << (int)today.month << "/"
  55.                     << (int)today.day << " ";
  56.         ofile << (int)now.hour << ":"
  57.                     << (int)now.minute << ":"
  58.                     << (int)now.second << ":"
  59.                     << (int)now.hsecond << "\n";
  60.  
  61.         ofile.close();
  62.     }
  63.  
  64.     clrscr();
  65.  
  66.     char *password;
  67.  
  68.     // get the password from the user up to 8 characters
  69.     password = getpass("Enter password:");
  70.  
  71.     // convert to upper case for comparison
  72.     int length = strlen(password);
  73.     for (int i=0; i<length; i++)
  74.     {
  75.          password[i] = toupper(password[i]);
  76.     }
  77.  
  78.  
  79.     // check the password, change the value in the quotes for new password
  80.     if(!strcmp("PASSWORD", password) == 0) {
  81.  
  82.         // The location of the reset flag
  83.         int far *Reset_Flag = (int far *)0x0472L;
  84.  
  85.         // this value indicates a warm boot is to be performed
  86.         Reset_Flag[0] = 0x1234;
  87.  
  88.         // here it is the BASM code to perform the boot
  89.         asm {
  90.             db 0xea
  91.             dw 0x00
  92.             dw 0xffff
  93.         }
  94.     }
  95.  
  96.     return 0;
  97.  
  98. }
  99.  
  100.